<?php
/* @var $this InstrumentController */
/* @var $model Instrument */

$this->breadcrumbs=array(
	'大型仪器管理'=>array('admin'),
	$model->title,
);

$this->menu=array(
	array('label'=>'返回大型仪器管理', 'url'=>array('admin')),
	array('label'=>'更新当前大型仪器类', 'url'=>array('update', 'id'=>$model->instrument_id)),
	array('label'=>'删除当前大型仪器类', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->instrument_id),'confirm'=>'Are you sure you want to delete this item?')),
	array('label'=>'录入仪器信息', 'url'=>array('createElem','iid'=>$model->instrument_id)),
	array('label'=>'录入时间表', 'url'=>array('createDate','iid'=>$model->instrument_id)),
);
?>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
    <li class="active"><a href="#home" role="tab" data-toggle="tab">基本信息</a></li>
    <li><a href="#instrumenlist" role="tab" data-toggle="tab">仪器列表</a></li>
    <li><a href="#datetable" role="tab" data-toggle="tab">开放时间表</a></li>
    <li><a href="#bookinfo" role="tab" data-toggle="tab">预约情况（图）</a></li>
    <li><a href="#infotable" role="tab" data-toggle="tab">预约情况（表）</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
    <div class="tab-pane active" id="home">
        <h2>当前大型仪器类信息 #<?php echo $model->title; ?></h2>
        <table class="table table-bordered">
        <tbody>
            <tr>
                <td rowspan=5 colspan=4 style="width:300px">
                    <img src="<?php echo yii::app()->baseUrl.'/'.$model->resources->description.$model->resources->fileName?>" width=300px/>
                </td>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('price')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->price;?>
                </td>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('brand')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->brand;?>
                </td>

            </tr>
            <tr>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('status')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->getEnabledLable();?>
                </td>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('stock')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->stock;?>
                </td>

            </tr>
            <tr>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('model')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->model;?>
                </td>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('total_stock')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->total_stock;?>
                </td>

           </tr>
            <tr>
               
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('specification')); ?>:</b>
                </td>
                <td>
                   <?php echo $model->specification;?>
                </td>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('origin')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->origin;?>
                </td>
            </tr>
            <tr>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('contacts')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->contacts;?>
                </td>
                <td>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('place')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->place;?>
                </td>
            </tr>
            <tr>
                <td width=90>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('subordinate_units')); ?>:</b>
                </td>
                <td colspan=3>
                    <?php echo $model->subordinate_units;?>
                </td>
                <td width=90>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('production_date')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->production_date;?>
                </td>
                <td width=90>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('purchase_date')); ?>:</b>
                </td>
                <td>
                    <?php echo $model->purchase_date;?>
                </td>

            </tr>
            <tr>
                <td width=90>
	                <b><?php echo CHtml::encode($model->getAttributeLabel('manufacturer')); ?>:</b>
                </td>
                <td colspan=7>
                   <?php echo $model->manufacturer;?>
                </td>
            </tr>
        </tbody>
    </table>
    <h4><?php echo CHtml::encode($model->getAttributeLabel('description'));?></h4>
    <div><?php echo $model->description;?></div>
    </div>
    <div class="tab-pane" id="instrumenlist">
        <h2>仪器列表</h2>
        <?php $this->widget('zii.widgets.grid.CGridView', array(
            'id'=>'instrument-elem-grid',
            'dataProvider'=>$modelElem->search($model->instrument_id),
            'filter'=>$modelElem,
            'columns'=>array(
                array(
                    'name'=>'elem_id',
                    'type'=>'raw',
                    'value'=>'CHtml::link($data->elem_id,array("viewElem","id"=>$data->elem_id))',
                ),
                'instrument.title',
                'asset_number',
     /*           'current_user',
                'frequency',
                'usedtime',*/
                array(
                    'name'=>'status',
                    'value'=>'$data->getEnabledLable()',
                ),
                array(
                    'class'=>'CButtonColumn',
                    'template'=>'{view}{update}{delete}',
                    'buttons'=>array(
                        'view' => array(
                            'url'=>'Yii::app()->createURL("admin/instrument/viewElem", array("id"=>"$data->elem_id"))',
                        ),
                        'update' => array(
                            'url'=>'Yii::app()->createURL("admin/instrument/updateElem", array("id"=>"$data->elem_id"))',
                        ),
                        'delete' => array(
                            'url'=>'Yii::app()->createURL("admin/instrument/deleteElem", array("id"=>"$data->elem_id"))',
                        ),
                    ),
                    'header'=>'操作',
                ),
            ),
        )); ?>
    </div>
    <div class="tab-pane" id="datetable">
    <h2>时间表</h2>
        <?php $this->widget('zii.widgets.grid.CGridView', array(
            'id'=>'instrument-date-grid',
            'dataProvider'=>$modelDate->search($model->instrument_id),
            'filter'=>$modelDate,
            'columns'=>array(
                array(
                    'name'=>'date_id',
                    'type'=>'raw',
                    'value'=>'CHtml::link($data->date_id,array("viewDate","id"=>$data->date_id))',
                ),
                array(
                    'name'=>'start_date',
                    'type'=>'raw',
                    'value'=>'CHtml::link(date("Y-m-d",strtotime($data->start_date)),array("viewDate","id"=>$data->date_id))',
                ),
                array(
                    'name'=>'end_date',
                    'type'=>'raw',
                    'value'=>'CHtml::link(date("Y-m-d",strtotime($data->end_date)),array("viewDate","id"=>$data->date_id))',
                ),
                array(
                    'name'=>'start_time',
                    'type'=>'raw',
                    'value'=>'CHtml::link(date("H",strtotime($data->start_date)),array("viewDate","id"=>$data->date_id))',
                ),
                array(
                    'name'=>'end_time',
                    'type'=>'raw',
                    'value'=>'CHtml::link(date("H",strtotime($data->end_date)),array("viewDate","id"=>$data->date_id))',
                ),
                array(
                    'name'=>'enabled',
                    'value'=>'$data->getEnabledLable()',
                ),
                array(
                    'class'=>'CButtonColumn',
                    'template'=>'{view}{update}{delete}',
                    'buttons'=>array(
                        'view' => array(
                            'url'=>'Yii::app()->createURL("admin/instrument/viewDate", array("id"=>"$data->date_id"))',
                        ),
                        'update' => array(
                            'url'=>'Yii::app()->createURL("admin/instrument/updateDate", array("id"=>"$data->date_id"))',
                        ),
                        'delete' => array(
                            'url'=>'Yii::app()->createURL("admin/instrument/deleteDate", array("id"=>"$data->date_id"))',
                        ),
                    ),
                    'header'=>'操作',
                ),
            ),
        )); ?>
    <?php
    /**
     * =========================================================================
     *                      根据上方时间表 生成预约时间表
     * =========================================================================
     */
    ?>
        <h2>生成预约时间表</h2>
        <?php echo $this->renderPartial('_datetable', array('dateTable'=>$dateTable, 'model'=>$model)); ?>
    </div>
    <div class="tab-pane" id="bookinfo">
        <h2>当前预约情况</h2>
        <?php echo $this->renderPartial('_statisticsdatetable', array('dateTable'=>$dateTableInfo, 'model'=>$model)); ?>
    </div>
    <div class="tab-pane" id="infotable">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'message-form',
    'enableAjaxValidation'=>false,
));?>
<h4>待审核的预约</h4>
<script>
function pass(){
if(!confirm("您确定要将下表中被勾选的预约设置为已通过吗？"))
{
return false;
}
}
function refuse(){
if(!confirm("您确定要将下表中被勾选的预约设置为未通过吗？"))
{
return false;
}
}
</script>

<p style="text-align:left;margin-bottom:0px">
    <button type="submit" class="btn btn-default" name="submitPass" onclick="return pass()">通过</button> 
    <button type="submit" class="btn btn-default" name="submitRefuse" onclick="return refuse()">拒绝</button> 
</p>
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'instrument-reserve-grid-1',
    'dataProvider'=>$modelInfo->searchPend($model,InstrumentReserve::STATUS_WAIT_EXAMINE),
    'filter'=>$modelInfo,
    'columns'=>array(
        array(
            'selectableRows' => 2,
            'class' => 'CCheckBoxColumn',
            'headerHtmlOptions' => array('width'=>'33px','style'=>'text-align:center'),
            'checkBoxHtmlOptions' => array('name' => 'select[]'),
            'htmlOptions'=>array(
                'style'=>'text-align:center',
            ),
        ),
        'reserve_id',
        array(
			'name'=>'instrument_id',
            'value'=>'$data->instrument->title',
        ),
        array(
			'name'=>'user_id',
            'value'=>'$data->user->user_name',
        ),
        array(
            'name'=>'start_date',
            'value'=>'$data->getFormatTime()',
        ),
        array(
            'name'=>'status',
            'value'=>'$data->getStatusText()',
        ),
    ),
)); ?>
<?php $this->endWidget(); ?>

<h4>已审核的预约</h4>
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'instrument-reserve-grid-2',
    'dataProvider'=>$modelInfo->searchPend($model,-1),
    'filter'=>$modelInfo,
    'columns'=>array(
        'reserve_id',
        array(
			'name'=>'elem_id',
            'value'=>'$data->instrumentElem->asset_number',
        ),
        array(
			'name'=>'user_id',
            'value'=>'$data->user->user_name',
        ),
        array(
            'name'=>'start_date',
            'value'=>'$data->getFormatTime()',
        ),
        array(
            'name'=>'status',
            'value'=>'$data->getStatusText()',
        ),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{delete}',
            'buttons'=>array(
                'delete'=>array(
                    'url'=>'Yii::app()->createURL("instrument/deleteReserve", array("id"=>"$data->reserve_id"))',
                ),
            ),
            'header'=>'操作',
        ),
    ),
)); ?>
<h4>已过期的预约</h4>
<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'instrument-reserve-grid-3',
    'dataProvider'=>$modelInfo->searchPass($model),
    'filter'=>$modelInfo,
    'columns'=>array(
        'reserve_id',
        array(
			'name'=>'elem_id',
            'value'=>'$data->instrumentElem->asset_number',
        ),
        array(
			'name'=>'user_id',
            'value'=>'$data->user->user_name',
        ),
        array(
            'name'=>'start_date',
            'value'=>'$data->getFormatTime()',
        ),

    ),
)); ?>

    </div>
 
    </div>
</div>


